using System.Collections;
using System.Collections.Generic;
using QFramework;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;

public class PropItem : MonoBehaviour,IController
{
    public Image icon;
    public Text name;
    public Text num;
    public Button button;
    public PropDataData propDataData;
    public int curNum;

    public IArchitecture GetArchitecture() => GameArchitecture.Interface;

    public void SetData(PropDataData propDataData)
    {
        this.propDataData = propDataData;

        curNum = propDataData.number;

        icon.sprite = propDataData.propData.icon;
        name.text = propDataData.propData.name;
        num.text = curNum.ToString();
        button.onClick.AddListener(OnClickButton);
    }

    public void ReSet()
    {
        curNum = propDataData.number;
        icon.sprite = propDataData.propData.icon;
        name.text = propDataData.propData.name;
        num.text = curNum.ToString();
    }

    public void ChangeNum(int changeNum)
    {
        curNum = changeNum;
        num.text = curNum.ToString();
    }

    private void OnClickButton()
    {
        var audioSystem = this.GetSystem<AudioSystem>();
        audioSystem.PlaySoundEffect("Sound/effects/button04b");
        Debug.Log(propDataData.propData.name);
        if(curNum > 0)
        {
            this.GetSystem<PropSetSystem>().MouseGetProp(propDataData.propData);
        }
    }
}
